package com.neusoft.nepm.exception;

import com.neusoft.nepm.vo.ResponseData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Arrays;

/**
 * @author zouran
 * createDate：2023/6/19  21:01
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     *description:other exception
     */
    @ExceptionHandler(value=cn.dev33.satoken.exception.NotLoginException.class)
    public ResponseData<Object> ExceptionHandler(cn.dev33.satoken.exception.NotLoginException e){
        ResponseData<Object> responseData=new ResponseData<>();
        responseData.setCode(0);
        responseData.setMessage("未登录");
        responseData.setResult(null);
        return responseData;
    }
    /**
     *description:other exception
     */
    @ExceptionHandler(value=Exception.class)
    public ResponseData<Object> ExceptionHandler(Exception e){
        e.printStackTrace();
        log.info("Exception");
        log.info(e.toString());
        System.out.println(Arrays.toString(e.getStackTrace()).split(",")[0]);
        ResponseData<Object> responseData=new ResponseData<>();
        responseData.setCode(500);
        responseData.setMessage("服务器内部异常");
        responseData.setResult(null);
        return responseData;
    }
}
